﻿using System;
using System.Management;

namespace LcfContols.asyncMessage
{
    /// <summary>
    /// 系统信息
    /// </summary>
    public class SystemUtils
    {
        /// <summary>
        /// 获取系统中CPU线程数
        /// </summary>
        /// <returns></returns>
        public static int NumberOfLogicalProcessors()
        {
            int recvThreads = 0;
            ManagementClass mc = new ManagementClass("win32_processor");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                PropertyDataCollection properties = mo.Properties;
                recvThreads += Convert.ToUInt16(properties["NumberOfLogicalProcessors"].Value);
            }
            if (recvThreads == 0)
                recvThreads = 2;
            return recvThreads;
        }


    }
}
